package se.chalmers.tda366.crumble.utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public final class DateParser {

	public static final SimpleDateFormat rfc822DateFormats[] = new SimpleDateFormat[] { 
		new SimpleDateFormat("EEE, d MMM yy HH:mm:ss z", Locale.US), 
		new SimpleDateFormat("EEE, d MMM yy HH:mm z", Locale.US), 
		new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", Locale.US), 
		new SimpleDateFormat("EEE, d MMM yyyy HH:mm z", Locale.US), 
		new SimpleDateFormat("d MMM yy HH:mm z", Locale.US), 
		new SimpleDateFormat("d MMM yy HH:mm:ss z", Locale.US), 
		new SimpleDateFormat("d MMM yyyy HH:mm z", Locale.US), 
		new SimpleDateFormat("d MMM yyyy HH:mm:ss z", Locale.US)}; 
	

	
	public static Date parseString(String text){
		Date date = null;
		for(int i=0; i<rfc822DateFormats.length; i++){
			if(date==null)
				date = rfc822DateFormats[i].parse(text, new ParsePosition(0));
		}
		return date;
	}

}
